#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 设置表格的列数--》字段数目(姓名，班级，成绩)
    ui->tableWidget->setColumnCount(3); // 3列

    // 设置表格的字段名字
    ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "姓名" << "班级" << "成绩");

    // 设置表格行数
    ui->tableWidget->setRowCount(10);

    // 设置文本内容
    ui->tableWidget->setItem(0, 0, new QTableWidgetItem("江锐"));
    ui->tableWidget->setItem(0, 1, new QTableWidgetItem("GZ25合班6"));
    ui->tableWidget->setItem(0, 2, new QTableWidgetItem("100"));

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("马云"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("GZ25合班6"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("80.5"));
}

MainWindow::~MainWindow()
{
    delete ui;
}

// 查找
void MainWindow::on_pushButton_clicked()
{
    // 获取查找的内容
    QString msg = ui->lineEdit->text();

    // 查找
    auto ret = ui->tableWidget->findItems(msg, Qt::MatchContains);
    if (ret.size() != 0)
        QMessageBox::question(this, "找到了", "恭喜找到了");
    else
        QMessageBox::warning(this, "没有找到", "不存在这个内容");
}
// 删除
void MainWindow::on_pushButton_2_clicked()
{
    QString r = ui->lineEdit_2->text();
    QString c = ui->lineEdit_3->text();
    ui->tableWidget->takeItem(r.toInt(), c.toInt());
}
